use poker_lib::PokerCard;

#[derive(Copy, Clone, Debug)]
pub struct TeamScore {
    pub id: u8,
    pub bid: i16,
    pub tricks: i16,
    pub nil_bonus: i16,
    pub bags: i16,
    pub total_bags: i16,
    pub bag_penalty: i16,
    pub bid_score: i16,
    pub round_score: i16,
    pub match_score: i16,
    pub bid_nil: u8,
}

impl TeamScore {
    pub fn new(id: u8) -> Self {
        TeamScore {
            id: id,
            bid: 0,
            tricks: 0,
            nil_bonus: 0,
            bags: 0,
            total_bags: 0,
            bag_penalty: 0,
            bid_score: 0,
            round_score: 0,
            match_score: 0,
            bid_nil: 0,
        }
    }
    // pub fn reset(&mut self) {
    //     self.bid = 0;
    //     self.tricks = 0;
    //     self.nil_bonus = 0;
    //     self.bags = 0;
    //     self.total_bags = 0;
    //     self.bag_penalty = 0;
    //     self.bid_score = 0;
    //     self.round_score = 0;
    //     self.match_score = 0;
    // }
}
#[derive(Debug, Clone, Copy)]
pub struct TeamState {
    pub id: usize,
    pub score: i16,
    pub bags: i16,
}
impl TeamState {
    pub fn new(id: usize) -> Self {
        TeamState {
            id: id,
            score: 0,
            bags: 0,
        }
    }
}
#[derive(Debug,Clone)]
pub struct PlayerScore {
    pub bid: i16,
    pub tricks: i16,
    pub nil_bonus: i16,
    pub score: i16,
    pub bags: i16,
    pub pile: Vec<PokerCard>,
}

impl PlayerScore {
    pub fn new() -> Self {
        PlayerScore {
            bid: 0,
            tricks: 0,
            nil_bonus: 0,
            score: 0,
            bags: 0,
            pile: vec![],
        }
    }
    // pub fn apply(&mut self, bid: i32, tricks: i32) {
    //     self.bid = bid;
    //     self.tricks = tricks;
    // }
    // pub fn set_nil_bounus(&mut self,nil_bonus:i32 ) {
    //     self.nil_bonus = nil_bonus;
    // }
}
#[derive(Debug,Clone)]
pub struct RoundResult {
    ///每500一局中的回合数
    pub round_number: i32,
    ///记录团队的累积分数
    pub teams: [TeamScore; 4],
    ///记录每个玩家的累积分数
    pub players: [PlayerScore; 4],
    ///记录每个玩家黑桃杀胜利的次数
    pub players_break_win: [u8; 4],
    ///记录每个玩家最少的花色数量
    pub players_min_suit: [u8; 4],
    ///记录每个玩家主牌的数量
    pub players_spades_suit: [u8; 4],
    ///获胜队伍
    pub win_team_id: u8,
    pub is_win_bid_nil:i8,
    ///破黑桃
    pub spades_broken: u8,
    ///黑桃杀的次数
    pub spades_break_times: u8,
    ///是否有破袋的情况
    pub has_bag_penalty:bool,
}

impl RoundResult {
    pub fn new() -> Self {
        RoundResult {
            round_number: 0,
            teams: [
                TeamScore::new(0),
                TeamScore::new(1),
                TeamScore::new(2),
                TeamScore::new(3),
            ],
            players: [
                PlayerScore::new(),
                PlayerScore::new(),
                PlayerScore::new(),
                PlayerScore::new(),
            ],
            win_team_id: 0,
            players_break_win: [0, 0, 0, 0],
            spades_broken: 0,
            spades_break_times: 0,
            players_min_suit: [0, 0, 0, 0],
            players_spades_suit: [0, 0, 0, 0],
            is_win_bid_nil:-1,
            has_bag_penalty: false
        }
    }

    // pub fn to_string(&self) -> String {
    //     let mut result = String::new();
    //     result.push_str(&format!("Round Number: {}\n", self.round_number));

    //     for (i, team) in self.teams.iter().enumerate() {
    //         result.push_str(&format!("Team {}:\n", i + 1));
    //         result.push_str(&format!("  Bid: {}\n", team.bid));
    //         result.push_str(&format!("  Tricks: {}\n", team.tricks));
    //         result.push_str(&format!("  Nil Bonus: {}\n", team.nil_bonus));
    //         result.push_str(&format!("  Bags: {}\n", team.bags));
    //         result.push_str(&format!("  Total Bags: {}\n", team.total_bags));
    //         result.push_str(&format!("  Bag Penalty: {}\n", team.bag_penalty));
    //         result.push_str(&format!("  Bid Score: {}\n", team.bid_score));
    //         result.push_str(&format!("  Round Score: {}\n", team.round_score));
    //         result.push_str(&format!("  Match Score: {}\n", team.match_score));
    //     }

    //     for (i, player) in self.players.iter().enumerate() {
    //         result.push_str(&format!("Player {}:\n", i + 1));
    //         result.push_str(&format!("  Bid: {}\n", player.bid));
    //         result.push_str(&format!("  Tricks: {}\n", player.tricks));
    //         result.push_str(&format!("  Nil Bonus: {}\n", player.nil_bonus));
    //     }
    //     result
    // }
}
